package cn.edu.cdu.group4nb.controller;

import cn.edu.cdu.group4nb.service.AttendenceService;
import cn.edu.cdu.group4nb.utils.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
public class AttendenceController {
    @Autowired
    private AttendenceService attendenceService;

    @ResponseBody
    @RequestMapping(value = "/AttendenceManager/selectAttend")
    public List<Map<String, Object>> selectAttend(String userid) {
        List<Map<String, Object>> list = attendenceService.selectAttend(userid);
        return list;
    }

    @ResponseBody
    @RequestMapping(value = "/AttendenceManager/selectUserAttend")
    public List<Map<String, Object>> selectUserAttend() {
        String Userid = ShiroUtils.getUserEntity().getUserid();
        List<Map<String, Object>> list = attendenceService.selectUserAttend(Userid);
        return list;
    }

    @ResponseBody
    @RequestMapping(value = "/AttendenceManager/inTime")
    public Boolean insertTime() {
        int user_info_id = ShiroUtils.getUserEntity().getUserInfoId();
        System.out.println(user_info_id);
        String Userid = ShiroUtils.getUserEntity().getUserid();
        return attendenceService.insertTime(user_info_id);
    }

    @ResponseBody
    @RequestMapping(value = "/AttendenceManager/selectUser")
    public List<Map<String, Object>> selectUser() {
        return attendenceService.selectUser();
    }

    @ResponseBody
    @RequestMapping(value = "/AttendenceManager/updateOutTime")
    public Boolean updateOutTime() {
        int user_info_id = ShiroUtils.getUserEntity().getUserInfoId();
        return attendenceService.selectInTime(user_info_id);
    }

    @ResponseBody
    @RequestMapping(value = "/AttendenceManager/ifTime")
    public Boolean ifTime() {
        int user_info_id = ShiroUtils.getUserEntity().getUserInfoId();
        return attendenceService.ifTime(user_info_id);

    }
}
